<template>
    <div>
        <div>
            <el-dialog class="nyDialog" :visible.sync="is_dialog_show" width="42%" :close-on-click-modal="false"
                :before-close="() => { this.close(); }">
                <div class="overflow-hidden w-full h-full flex flex-col items-center" style="border-radius:4px;">
                    <div class="w-full h-w48 flex items-center px-w20 justify-between bg-caux text-white">
                        <div class="text-f14">{{ type == 1 ? "添加基本信息" : "添加问卷问题" }}</div>
                        <i class="el-icon-circle-close   cursor-pointer" @click.stop="close()"></i>
                    </div>
                    <div class="w-full flex justify-center">
                        <div class="flex flex-col w-w10/12  ">
                            <div class="flex flex-row items-center  w-full h-w50 leading-w50 text-c3 text-f16  mt-w30">
                                <div class=" w-w1/4 text-right pr-w20">{{ type == 1 ? "基本信息名称" : "问卷问题名称" }}</div>
                                <el-input class="w-w3/4" placeholder="请输入内容" v-model="m_data.name" clearable autofocus>
                                </el-input>
                            </div>
                            <div class="flex flex-row items-center  w-full h-w50 leading-w50 text-c3 text-f16  mt-w30">
                                <div class=" w-w1/4 text-right pr-w20">填写方式</div>
                                <el-radio-group class="w-w3/4" v-model="m_data.inputType">
                                    <el-radio :label="1">手动输入</el-radio>
                                    <el-radio :label="2">单选</el-radio>
                                    <el-radio :label="3">多选</el-radio>
                                </el-radio-group>
                            </div>
                            <div class="flex flex-row items-center  w-full min-h-w50 leading-w50 text-c3 text-f16  mt-w30"
                                v-if="m_data.inputType == 2 || m_data.inputType == 3">
                                <div class=" w-w1/4 text-right pr-w20">设置选项内容</div>
                                <div class="w-w3/4">
                                    <!-- <el-input class="w-full h-w50" placeholder="请输入内容" v-model="m_data.name" clearable>
                                    </el-input> -->
                                    <el-select class="w-full" v-model="m_data.contentList" multiple filterable
                                        allow-create default-first-option placeholder="请输入选项内容">
                                        <!-- <el-option v-for="item in options" :key="item.value" :label="item.label"
                                            :value="item.value">
                                        </el-option> -->
                                    </el-select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="w-full flex flex-row justify-center mt-w30 mb-w30">
                        <el-button class=" w-w1/5 mr-w20" @click="close">取消</el-button>
                        <el-button class=" w-w1/5 bg-cmain_hover" type="primary" @click="actionSubmit">确定
                        </el-button>
                    </div>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
<script lang="ts">
import nyMessageToast from "@/utils/NYMessageToast";
import DZModelQuesiton from "@/views/问卷管理/model/DZModelQuesiton";
import { Component, Vue, Prop, Watch } from "vue-property-decorator";

@Component
export default class UiDialogAddBase extends Vue {

    @Prop() is_showDialog;

    // @Prop() data;

    @Prop({ default: 1 }) type;

    is_dialog_show = false;

    m_data = new DZModelQuesiton();



    created() { }

    mounted() {
    }

    beforeDestroy() { }

    close() {
        this.$emit('nydialog_closed', '');
        this.initDialog();
    }
    initDialog() {
        this.m_data = new DZModelQuesiton();
        this.is_dialog_show = false;
    }

    @Watch("is_showDialog")
    watchShowDialog(value: any, oldValue: string) {
        this.is_dialog_show = value;
    }

    // @Watch("data")
    // watchData(value: any, oldValue: string) {
    //     if (value) {
    //         this.m_data = value;
    //     } else {
    //         this.m_data = new DZModelQuesiton();
    //     }
    // }


    actionSubmit() {
        if (this.m_data.name.nyIsEmpty()) {
            nyMessageToast.error("请输入信息名称")
            return;
        }
        if (this.m_data.inputType == 0) {
            nyMessageToast.error("请选择输入方式")
            return;
        }
        if ((this.m_data.inputType == 2 || this.m_data.inputType == 3) && this.m_data.contentList.length == 0) {
            nyMessageToast.error("请设置选项内容")
            return;
        }
        if (this.m_data.inputType == 2 || this.m_data.inputType == 3) {
            this.m_data.selectContent = this.m_data.contentList.join(",");
        }
        this.$emit('nydialog_submit', this.m_data);
        this.close();
    }
}
</script>
<style lang="less" scoped>
/deep/ .el-dialog {
    border-radius: 4px !important;
    border: none;
}

/deep/.el-dialog__body {
    text-align: left;
    // min-height: 22vw;
    padding: 0px;
}

/deep/ .dialog-tips {
    margin-top: 0 !important;
}

/deep/ .el-dialog__footer {
    text-align: right;
}

/deep/.el-dialog__header {
    height: 0px;
    padding: 0;
}

/deep/ .el-icon-close:before {
    content: '';
}

.nyDialog {
    background: none;
}
</style>
